//
//  CCNavigationController.m
//  BuDeJie
//
//  Created by demoncraz on 2017/2/10.
//  Copyright © 2017年 demoncraz. All rights reserved.
//

#import "CCNavigationController.h"

@interface CCNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation CCNavigationController

+ (void)load {
    //navigationBar背景颜色
    UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[self]];
    navBar.barTintColor = DefaultBackgroundColor;
    navBar.translucent = NO;
    //去掉边框线
    [navBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [navBar setShadowImage:[UIImage new]];
    
    navBar.titleTextAttributes = @{
                                   NSForegroundColorAttributeName : [UIColor whiteColor]
                                   };
}

- (void)viewDidLoad {
    /*
     <UIScreenEdgePanGestureRecognizer: 0x7fd1c360d9f0; state = Possible; enabled = NO; delaysTouchesBegan = YES; view = <UILayoutContainerView 0x7fd1c360cf20>; target= <(action=handleNavigationTransition:, target=<_UINavigationInteractiveTransition 0x7fd1c360d8b0>)>>
     */
    
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //全屏滑动返回
    self.interactivePopGestureRecognizer.enabled = NO;
    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
    
    [self.view addGestureRecognizer:pan];
    
    pan.delegate = self;
    
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    return self.childViewControllers.count > 1;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.childViewControllers.count > 0) {
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem backButtonItemWithImage:[UIImage imageNamed:@"nav_back_item_wihite_15x21_"] selImage:[UIImage imageNamed:@"nav_back_item_wihite_click_15x21_"] target:self action:@selector(back)];
        //隐藏tabbar栏
         viewController.hidesBottomBarWhenPushed = YES;
    }
    
    [super pushViewController:viewController animated:animated];
}

- (void)back {
    [self popViewControllerAnimated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
